﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers;
using eTMS.Controllers.ChuongTrinhDaoTaoService;
using eTMS.Commons;

namespace eTMS.Forms.ManageList
{
    public partial class FrmKhoaHocSuDungCTDT : eTMS.Controls.BaseForm
    {
        public FrmKhoaHocSuDungCTDT()
        {
            InitializeComponent();
        }

        private KhoaHocController controller;
        public void SetController(KhoaHocController khoaHocController)
        {
            controller = khoaHocController;
        }
        ChuongTrinhDaoTaoController ctrChuongTrinhDTCtr = new ChuongTrinhDaoTaoController();
        private void LoadData()
        {
            label1.Text = "Khóa học:" + controller.KhoaHocObject.TenKhoaHoc;
            ChuongTrinhDaoTaoController.LoadAllChuongTrinhDaoTao(false);
            controller.LoadAllDSNganhSuDungChuongTrinhDaoTao();
            Column3.DisplayMember = "TenCTDaoTao";
            Column3.ValueMember = "ChuongTrinhDaoTao_ID";
            Column3.DataSource = ctrChuongTrinhDTCtr.ListChuongTrinhDaoTao;
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = controller.TableApDung;
            ChuongTrinhDaoTaoController.LoadAllChuongTrinhDaoTao(false);
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataRowView row = (DataRowView)dataGridView1.Rows[i].DataBoundItem;
                DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
                List<ChuongTrinhDaoTaoEntity> ls = new List<ChuongTrinhDaoTaoEntity>();
                ChuongTrinhDaoTaoEntity o = new ChuongTrinhDaoTaoEntity();
                o.TenCTDaoTao = Constants.APP_CHOOSE;
                o.ChuongTrinhDaoTao_ID = 0;
                ls.Add(o);
                ls.AddRange( ctrChuongTrinhDTCtr.ListChuongTrinhDaoTao.FindAll(delegate(ChuongTrinhDaoTaoEntity ofind) { return ofind.NganhHoc_ID == (int)row["NganhHoc_ID"]; }));
                cmb.DisplayMember = "TenCTDaoTao";
                cmb.ValueMember = "ChuongTrinhDaoTao_ID";
                cmb.DataSource = ls;
                dataGridView1.Rows[i].Cells[2] = cmb;
            }
        }

        private void FrmKhoaHocSuDungCTDT_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void ucCommandDialog1_OnOK(object sender, CancelEventArgs e)
        {
            controller.SaveDSNganhSuDungChuongTrinhDaoTao();
        }

    }
}
